interface Square{
    color:string
    area:number
}

interface SquareConfig{//可选属性
    color?:string
    width?:number
    [propName:string]:any //额外属性检查
}

function createSquare(config:SquareConfig):Square{
    let newSquare = {color:'white',area:100}
    if(config.color){
        newSquare.color = config.color
    }
    if(config.width){
        newSquare.area=config.width*config.width
    }
    return newSquare
}

let mySqquar=createSquare({colour:'black'})



//函数类型
interface SearchFunc {
    (source:string,substring:string):boolean
}
let mySearch:SearchFunc
mySearch=function (src:string,sub:string):boolean{
    let result=src.search(sub)
    return result >-1
}

//函数索引
interface StringArray{
    [index:number]:string
}
let myArray:StringArray
myArray=['Bob','Fred']
let myStr:string=myArray['0']

//可索引类型
class Animal {
    name:string
}
class Dog extends Animal{
    bread:string
}

//不能把 animal 复制给Dog

interface NotOkay{
    [x:number]:Dog

    [x:string]:Animal
}


interface NumberDictionary{
      [index:string]:number
      length:number
     // name:string  string类型不能复制给number类型
}

interface ReadonlyStringArray{
    readonly [index:number]:string
}
let myArrays:ReadonlyStringArray=['Alice','Li']
// myArrays[2]='ss';只读属性
